package com.ruoyi.framework.security.password.encoder;

import com.ruoyi.framework.security.context.IsPhoneLoginContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/***
 * @title MyBCryptPasswordEncoder
 * @description <description class purpose>
 * @author WeiShuo
 * @version 1.0.0
 * @create 2024/6/19 12:15
 **/
public class MyBCryptPasswordEncoder extends BCryptPasswordEncoder {


    /***
     * 重写匹配逻辑
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {

        //手机登录的密码匹配直接通过，无需验证密码
        if(IsPhoneLoginContextHolder.getContext() == null || !IsPhoneLoginContextHolder.getContext()) {
            return super.matches(rawPassword, encodedPassword);
        }else {
            return true;
        }
    }
}
